package com.j180.demo.controller.user;

import com.j180.demo.bean.ResultBean;
import com.j180.demo.bean.UserBean;
import com.j180.demo.service.user.IUserService;
import io.swagger.annotations.*;
import lombok.Getter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(value = "用户控制器")
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private IUserService iUserService;

    //用在方法上，描述该方法是处理什么的
    @ApiOperation(value = "登录方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "用户名"),
            @ApiImplicitParam(name = "密码"),
    })
    @GetMapping("/login")
    public ResultBean login(String username,
                            String password){
        ResultBean resultBean = new ResultBean();

        UserBean userBean = iUserService.login(username,password);

        if(userBean!=null){
            resultBean.setCode(0);
            resultBean.setMsg("登录成功");
            resultBean.setDatas(userBean);
        }else{
            resultBean.setCode(1);
            resultBean.setMsg("登录失败");
        }
        return resultBean;
    }

    @ApiOperation("测试方法")
    @GetMapping("/test")
    public String test(){

        return "hello swagger";
    }
}
